package xyz.chenyongpeng.utils;

import sun.util.resources.CalendarData;

import java.util.Calendar;

public class IDUtils {
    private static byte[] lock = new byte[0];

    // 位数，默认是8位
    private final static long w = 10000000;

    public static String createID() {
        Calendar calendar = Calendar.getInstance();
        int day = calendar.get(Calendar.DATE);

        long r = 0;
        synchronized (lock) {
            r = (long) ((Math.random() + 1) * w);
        }

        return day + "" + String.valueOf(r).substring(1);
//        return System.currentTimeMillis() + String.valueOf(r).substring(1);
    }


    public static void main(String[] args) {
        Calendar calendar = Calendar.getInstance();
        int day = calendar.get(Calendar.DATE);
        System.out.println();
        for (int i = 0; i < 10; i++) {
            System.out.println(day+""+IDUtils.createID());
        }
    }
}
